package com.audaque.springboot.foshanupload.web.webdemo.controller;

import cn.hutool.json.JSONUtil;
import com.audaque.springboot.foshanupload.httpclient.model.ExtractRestTemplate;
import com.audaque.springboot.foshanupload.log.anno.WebLogAnno;
import com.audaque.springboot.foshanupload.web.exception.RException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

/**
 * @author wangyan01
 */

@Slf4j
@RestController
@RequestMapping("log")
public class LogController  {


    @Autowired
    private ExtractRestTemplate extractRestTemplate;

    @WebLogAnno
    @GetMapping("restTemplate")
    public void restTemplate() throws Exception {
        long threadId = Thread.currentThread().getId();
        log.debug("threadId："+threadId);
        extractRestTemplate.getRestTemplateForIpPort().getForObject("http://localhost:8082/webdemo/log/test0",String.class);
    }
    @WebLogAnno
    @GetMapping("test0")
    public void test0() throws Exception {
        long threadId = Thread.currentThread().getId();
        log.debug("threadId："+threadId);
        // 等号
        log.debug("mobile={}", "13511114444");
        // 等号+[
        log.debug("mobile=[{}]", "13511114444");
        // 英文单引号+等号
        log.debug("mobile'='{}'", "13511114444");
        // 中文冒号
        log.debug("mobile：{}", "13511114444");
        // 英文冒号
        log.debug("mobile:{}", "13511114444");
        // 英文双引号+英文冒号
        log.debug("\"mobile\":\"{}\"", "13511114444");
    }


    @GetMapping("test1")
    public void test1() throws Exception {
        //11位手机号
        log.debug("mobile={}", "13511114444");
        log.debug("mobile={},手机号：{}", "13511112222", "13511113333");
        log.debug("手机号：{}", "13511115555");
        //固定电话（带区号-）
        log.debug("tel：{},座机={}", "0791-83376222", "021-88331234");
        log.debug("tel：{}", "0791-83376222");
        log.debug("座机={}", "021-88331234");

        //地址
        log.debug("address：{}", "浙江省杭州市西湖区北京西路100号");
        log.debug("地址：{}", "上海市浦东区北京东路1-10号");

        //19位卡号
        log.debug("cardNo：{}", "6227002020000101222");

        //姓名
        log.debug("name={}, 姓名=[{}]，name={}，姓名：{}", "张三", "上官婉儿", "李云龙", "楚云飞");

        //密码
        log.debug("password：{}，密码={}", "123456", "456789");
        log.debug("password：{}", "123456");
        log.debug("密码={}", "123456");

        //身份证号码
        log.debug("idCard：{}，身份证号={}", "360123202111111122", "360123202111111122");
        log.debug("身份证号={}", "360123202111111122");

        //邮箱
        log.debug("邮箱:{}", "wxyz123@qq.com");
        log.debug("email={}", "wxyz123@qq.com");
    }


    @GetMapping("test2")
    public void test2() throws Exception {
        User user = new User();
        user.setCardNo("6227002020000101222");
        user.setTel("0571-28821111");
        user.setAddress("浙江省西湖区西湖路288号钱江乐园2-101室");
        user.setEmail("zhangs12345@qq.com");
        user.setPassword("123456");
        user.setMobile("15911116789");
        user.setName("张三");
        user.setIdCard("360123202111111122");

        Job job = new Job();
        job.setAddress("浙江省西湖区西湖路288号钱江乐园2-101室");
        job.setTel("0571-12345678");
        job.setJobName("操作员");
        job.setSalary(2000);
        job.setCompany("股份有限公司");
        job.setPosition(Arrays.asList("需求", "开发", "测试", "上线"));

        user.setJob(job);

        //toString
        log.debug("用户信息：{}", user);
        //json
        log.debug("用户信息：{}", JSONUtil.toJsonStr(user));
    }

    @GetMapping("test3")
    public void test3() throws Exception {
        String format = String.format("%s", 9527);
        throw new RException("%s", 9527);
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    class User {
        private String cardNo;
        private String tel;
        private String address;
        private String email;
        private String password;
        private String mobile;
        private String name;
        private String idCard;
        private Job job;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    class Job {
        private String jobName;
        private String tel;
        private String address;
        private Integer salary;
        private String password;
        private String company;
        private List<String> position;
    }

}
